package algotithm.weekendrace.leetcode234.test1;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/28-10:26
 */
public class Solution {


    public static void main(String[] args) {
        Solution solution = new Solution();
//        String word = "a123bc34d8ef34";
//        String word = "167278959591294";
//        String word = "035985750011523523129774573439111590559325";
        String word = "a1b01c001";
        int i = solution.numDifferentIntegers(word);
        System.out.println(i);
    }

    public int numDifferentIntegers(String word) {
        Set<String> set = new HashSet<String>();
        StringBuffer sb = new StringBuffer();
        int length = word.length();
        for (int i = 0; i < length; i++) {
            char c = word.charAt(i);
            if (Character.isDigit(c)) {
                sb.append(c);
            } else {
                if (sb.length() > 0) {
                    String num = removeLeadingZeroes(sb.toString());
                    set.add(num);
                    sb.setLength(0);
                }
            }
        }
        if (sb.length() > 0) {
            String num = removeLeadingZeroes(sb.toString());
            set.add(num);
        }
        return set.size();
    }

    public String removeLeadingZeroes(String str) {
        int length = str.length();
        if (length == 1) {
            return str;
        }
        int start = 0;
        while (start < length) {
            if (str.charAt(start) != '0') {
                break;
            }
            start++;
        }
        return str.substring(start);
    }
}
